package com.ruoyi.web.controller.business;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.EmployeeScore;
import com.ruoyi.business.service.IEmployeeScoreService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 员工积分Controller
 *
 * @author ruoyi
 * @date 2024-11-30
 */
@Api(tags = "员工积分管理")
@RestController
@RequestMapping("/business/score")
public class EmployeeScoreController extends BaseController
{
    @Autowired
    private IEmployeeScoreService employeeScoreService;

    /**
     * 查询员工积分列表
     */
    @PreAuthorize("@ss.hasPermi('business:score:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询员工积分列表", notes = "根据条件查询员工积分列表")
    public TableDataInfo list(@ApiParam(value = "员工积分查询条件", required = false) EmployeeScore employeeScore)
    {
        startPage();
        List<EmployeeScore> list = employeeScoreService.selectEmployeeScoreList(employeeScore);
        return getDataTable(list);
    }

    /**
     * 导出员工积分列表
     */
    @PreAuthorize("@ss.hasPermi('business:score:export')")
    @Log(title = "员工积分", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出员工积分列表", notes = "导出符合条件的员工积分数据为Excel文件")
    public void export(HttpServletResponse response, @ApiParam(value = "员工积分查询条件", required = false) EmployeeScore employeeScore)
    {
        List<EmployeeScore> list = employeeScoreService.selectEmployeeScoreList(employeeScore);
        ExcelUtil<EmployeeScore> util = new ExcelUtil<EmployeeScore>(EmployeeScore.class);
        util.exportExcel(response, list, "员工积分数据");
    }

    /**
     * 获取员工积分详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:score:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取员工积分详细信息", notes = "根据ID获取员工积分详细信息")
    public AjaxResult getInfo(@ApiParam(value = "员工积分ID", required = true) @PathVariable("id") Long id)
    {
        return success(employeeScoreService.selectEmployeeScoreById(id));
    }

    /**
     * 新增员工积分
     */
    @PreAuthorize("@ss.hasPermi('business:score:add')")
    @Log(title = "员工积分", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增员工积分", notes = "新增一条员工积分记录")
    public AjaxResult add(@ApiParam(value = "员工积分对象", required = true) @RequestBody EmployeeScore employeeScore)
    {
        return toAjax(employeeScoreService.insertEmployeeScore(employeeScore));
    }

    /**
     * 修改员工积分
     */
    @PreAuthorize("@ss.hasPermi('business:score:edit')")
    @Log(title = "员工积分", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改员工积分", notes = "根据ID修改员工积分记录")
    public AjaxResult edit(@ApiParam(value = "员工积分对象", required = true) @RequestBody EmployeeScore employeeScore)
    {
        return toAjax(employeeScoreService.updateEmployeeScore(employeeScore));
    }

    /**
     * 删除员工积分
     */
    @PreAuthorize("@ss.hasPermi('business:score:remove')")
    @Log(title = "员工积分", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除员工积分", notes = "根据ID删除员工积分记录")
    public AjaxResult remove(@ApiParam(value = "员工积分ID数组", required = true) @PathVariable Long[] ids)
    {
        return toAjax(employeeScoreService.deleteEmployeeScoreByIds(ids));
    }

    /**
     * 首页的柱状图
     */
    @PostMapping("/bar")
    @ApiOperation(value = "获取首页柱状图数据", notes = "返回包含柱状图数据的JSON响应")
    public AjaxResult getBarData(@ApiParam(value = "员工积分查询条件", required = false) EmployeeScore employeeScore) {
        List<List<Object>> list = employeeScoreService.getBarData(employeeScore);
        return success(list);
    }

    /**
     * 饼图数据结构
     */
    @PostMapping("/pie")
    @ApiOperation(value = "获取首页饼图数据", notes = "返回包含饼图数据的JSON响应")
    public AjaxResult getPieData(@ApiParam(value = "员工积分查询条件", required = false) EmployeeScore employeeScore) {
        // 假设你有一个方法来获取饼图数据
        List<Map<String, Object>> pieData = employeeScoreService.getPieData(employeeScore);
        return success(pieData);
    }

    /**
     * 个人指标统计
     */
    @PostMapping("/getPersonalData")
    @ApiOperation(value = "获取个人柱状图数据", notes = "返回包含柱状图数据的JSON响应")
    public AjaxResult getPersonalData(@ApiParam(value = "个人指标统计", required = false) @RequestBody EmployeeScore employeeScore) {
        List<List<Object>> list = employeeScoreService.getPersonalData(employeeScore);
        return success(list);
    }

    /**
     * 个人年度星级
     */
    @PostMapping("/getRatingStar")
    @ApiOperation(value = "获取个人年度星级", notes = "返回包含个人年度星级数据的JSON响应")
    public AjaxResult getRatingStar(@ApiParam(value = "员工积分对象", required = true) @RequestBody EmployeeScore employeeScore) {
        List<Map<String, Object>> list = employeeScoreService.getRatingStar(employeeScore);
        return success(list);
    }
}
